#include "inoise.fxh"

Texture InputTexture;
int octaves = 3;
float lacunarity = 2.0;
float gain = 0.5;
float freq = 1.0;
float amp = 0.5;
int offset = 0;

sampler inputTexture = sampler_state 
{ 
    texture = <InputTexture>; 
    magfilter = LINEAR; 
    minfilter = LINEAR; 
    mipfilter = LINEAR; 
};
 
struct VS_OUTPUT
{
	float4 Position	: POSITION;
	float2 TexCoords : TEXCOORD0;
};

float4 interpolate(float4 c1, float4 c2, float n)
{
	float4 n4 = {n,n,n,n};
	return lerp(c1, c2, n4);
}
 
float4 Perlin_PS (VS_OUTPUT Input) : COLOR0
{
	float3 pos;
	pos.x = Input.TexCoords.x + offset;
	pos.y = 0;
	pos.z = Input.TexCoords.y + offset;
	float noise = fBm(pos, octaves, lacunarity, gain, freq, amp)*0.5+0.5;
	
	float4 c1 = {0.0, 0.0, 0.0, 1.0};
	float4 c2 = {1.0, 1.0, 1.0, 1.0};
	return interpolate(c1, c2, noise);
}
 
technique Perlin
{
	pass P0
	{
		PixelShader = compile ps_3_0 Perlin_PS();
	}
}